var UserManager = function(connection, userID, tokenID){
	var fn = this;
	var balance = 50000;
	fn.user = null;
	
	fn.init = function(){
		//fn.login();
	},
	
	fn.verifyUser = function(){
		
	},
	
	fn.login = function(successCallback, failCallback){
		fn.successCallback = successCallback;
		fn.failCallback = failCallback;
		connection.setUserVarsUpdateCallback(fn.onUserVarsUpdate);
		connection.login(userID, tokenID, fn.onLoginSuccess, fn.onLoginFail);
	},
	
	fn.logout = function(){
		connection.logout();
	},
	
	fn.onLoginSuccess = function(user){
		//fn.user = user;
		if(fn.successCallback){
			fn.successCallback();
		}
	},
	
	fn.onUserVarsUpdate = function(user){
		fn.user = user;
	},
	
	fn.onLoginFail = function(e){
		if(fn.failCallback){
			fn.failCallback();
		}
	},
	
	fn.getUserID = function(){
		return fn.user.id;
	},
	
	fn.getUsername = function(){
		return fn.user.name;
	},
	
	fn.getAvatar = function(){
		return fn.user.getVariable("avatar").value;
	},
	
	fn.getGender = function(){
		return fn.user.getVariable("gender").value;
	},
	
	fn.getBalance = function(){
		var balance = fn.user.getVariable("balance").value + "";
		var value = "";
		var isFirst = true;
		for(var i = balance.length - 1; i >= 0; i--){
			if(i % 3 == 1 && !isFirst){
				value = "." + value;
			}
			value = balance[i] + value;
			isFirst = false;
		}
		return value;
	}
};
